<?php
include_once("config.php");

if(!empty($_POST) && $_POST['act']!='save_default'){
	foreach ($_POST['title'] as $tk=>$tv)
	{
		$update_sql = "update ".WEBSEO." set ";
		$update_sql .= "title='{$tv}',";
		$update_sql .= "keywords='{$_POST['keywords'][$tk]}',";
		$update_sql .= "description='{$_POST['description'][$tk]}' where id='{$tk}'";
		$db->query($update_sql);
	}
}

if($_GET['act']=='default'){
	if($_POST['act']=='save_default'){
		$sql = "update ".WEBSEO." set title='{$_POST['d_title']}',keywords='{$_POST['d_keyword']}',description='{$_POST['d_description']}' where id='{$_POST['seo_id']}'";
		$db->query($sql);
	}
	
	$sql = "select * from ".WEBSEO." where module='default' and action='default'";
	$db->query($sql);
	$default = $db->fetchRow();
	$tpl->assign('default',$default);
}

$sql = "select module,module_name from ".WEBSEO." where module!='default' and action!='default' group by module";
$db->query($sql);
$module_list = $db->getRows();

$where = "";
if($_GET['module']){
	$where .= "and module='{$_GET['module']}'";
}
$sql = "select * from ".WEBSEO." where module!='default' and action!='default' {$where} order by module";
$db->query($sql);
$seo_list = $db->getRows();

$tpl->assign('module_list',$module_list);
$tpl->assign('seo_list',$seo_list);
$tpl->display('seo_manage.htm');
?>